package com.weitu.permission.authorityResource.service.impl;


import com.weitu.permission.authority.entity.AuthorityResource;
import com.weitu.permission.authorityResource.mapper.AuthorityResourceMapper;
import com.weitu.permission.authorityResource.service.AuthorityResourceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author LiMeng 2017/3/22
 */
@Service
public class AuthorityResourceServiceImpl implements AuthorityResourceService {
    private final AuthorityResourceMapper authorityResourceMapper;

    @Autowired
    public AuthorityResourceServiceImpl(AuthorityResourceMapper authorityResourceMapper) {
        this.authorityResourceMapper = authorityResourceMapper;
    }

    @Override
    @Transactional
    public boolean deleteAuthorityResourceByAuthorityId(String authorityId) {
        int count = authorityResourceMapper.deleteAuthorityResourceByAuthorityId(authorityId);
        return count > 0;
    }

    @Override
    @Transactional
    public boolean insertAuthorityResource(List<AuthorityResource> authorityResourceList) {
        int count = authorityResourceMapper.insertAuthorityResource(authorityResourceList);
        return count == authorityResourceList.size();
    }

    @Override
    @Transactional
    public boolean updateAuthorityResource(String authorityId, List<AuthorityResource> authorityResourceList) {
        authorityResourceMapper.deleteAuthorityResourceByAuthorityId(authorityId);
        int count = authorityResourceMapper.insertAuthorityResource(authorityResourceList);
        return count == authorityResourceList.size();
    }
}
